<?php

namespace services\models\minisite;

use Yii;

/**
 * This is the model class for table "d_mini.t_activity_show_feel_like_click".
 *
 * @property integer $id
 * @property integer $asf_id
 * @property string $c_open_id
 * @property string $db_time
 */
class MActivityShowFeelLikeClick extends \common\models\minisite\MActivityShowFeelLikeClick
{
    public function getMActivityShowFeel()
    {
        return $this->hasOne(MActivityShowFeel::className(), ['id' => 'asf_id']);
    }

    public static function clickLike($asf_id, $c_open_id)
    {
        if (static::findOne(['asf_id' => $asf_id, 'c_open_id' => $c_open_id]) !== null) {
            return false;
        } 
        
        $masflc = new MActivityShowFeelLikeClick();
        
        $masflc->asf_id = $asf_id;
        $masflc->c_open_id = $c_open_id;
        $masflc->db_time = date('Y-m-d H:i:s');
        
        return $masflc->save(true);


    }

    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);
        if ($insert && parent::beforeSave($insert)) {
            \services\models\minisite\MActivityShowFeelStatistics::updateAllCounters(['c_good_times'=>1], ['asf_id' => $this->asf_id]);
        }
    }
}
